﻿using System;
using System.Threading.Tasks;

namespace Ecobee.Net.Demo
{
	public class ListThermostatsCommand : CommandBase
	{
		public ListThermostatsCommand()
			: base("3", "List Thermostats")
		{
		}

		protected async override Task<bool> OnExcute(Api api)
		{
			bool returnValue = false;

			// ***
			// *** Call the ecobee API to get the list of thermostats. This call
			// *** returns summary data only (very limited). It is used to check
			// *** if anything has changed on a thermostat recently or to get the 
			// *** initial list.
			// ***
			ThermostatSummary thermostatSummary = new ThermostatSummary(api);

			if (await thermostatSummary.Request())
			{
				foreach (SummaryRevision summaryRevision in thermostatSummary.SummaryRevisionList)
				{
					Console.WriteLine("[{0}] {1}", summaryRevision.Identifier, summaryRevision.Name);
				}

				returnValue = true;
			}
			
			return returnValue;
		}
	}
}
